// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import EventManager from "../../../Common/EventManager";
import Loader from "../../../Common/Loader";
import yyComponent from "../../../Common/yyComponent";
import { EventType } from "../../../GameSpecial/GameEventType";
import { mgrs, sers } from "../../system/OverallSystem ";
import { GAME_MODE } from "../game/gameMode_Json";

const {ccclass, property} = cc._decorator;

@ccclass
export default class SignInItem extends yyComponent{

   

    // onLoad () {}

    @property(cc.Sprite)
    icon:cc.Sprite = null

 
    @property(cc.Label)
    gameNmae:cc.Label = null


    @property(cc.Node)
    yilingqu:cc.Node = null

  


    start () {
        // this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this)
        this.on(EventType.UIEvent.SignInList,this.updataView,this)
    }
    data = null
    setData(data){
        cc.log(data)
       this.data = data
       this.updataView()
    }

    updataView(){
        if(!this.data)return
        let data = this.data.data
        let wupin = this.data.wupinData
        

        // this.gameNmae.string = `${wupin[data['奖励物品ID']]['物品名称']}X${data['奖励物品数量']}`
        this.gameNmae.string = `X${data['奖励物品数量']}`



        let s = sers().userSrv.getSignInList()

        this.yilingqu.active = false
        if(s.list.indexOf(+data.key)>=0){
            this.yilingqu.active = true
        }

    //    let m = this.lockNode.active ? this.zhengchang : this.huise

    //    this.icon.setMaterial(0,m)
    //     this.icon.node.children[0].getComponent(cc.Sprite).setMaterial(0,m)
        let lujing = wupin[data['奖励物品ID']]['签到图标路径']
        Loader.loadBundleRes('home', 'image/'+lujing, (res) => {
        //    cc.log(res)
            if(!this || !this.node)return
            this.icon.spriteFrame = new cc.SpriteFrame(res)
        })
    }

    onTouchStart(){
        mgrs().soundMgr.playBtnSound();
    }

    // update (dt) {}
}
